const {Sequelize, DataTypes} = require("sequelize");
const start = require("./utils/connect");

(async()=>{
  const sequelize = await start();
  const CLASS = sequelize.define("CLASS",{
    name:{
      type:DataTypes.STRING,
      allowNull:false
    },
    uuid:{
      type:DataTypes.UUID,
      defaultValue:Sequelize.UUIDV1
    },
    member:{
      type:DataTypes.INTEGER.ZEROFILL
    }
  },{
    freezeTableName:true // 强制使用定义表名
  });

  const Student = sequelize.define("Student",{
    name:{
      type:DataTypes.STRING
    },
    age:{
      type:DataTypes.INTEGER,
      defaultValue:24
    },
    uuid:{
      type:DataTypes.UUID,
      defaultValue:Sequelize.UUIDV4
    }
  },{
    freezeTableName:true // 强制使用定义表名
  });

  Student.belongsTo(CLASS);


  await Student.sync({
    alter:true,
  });
  await CLASS.sync({
    alter:true,
  });


  const student1 = await Student.create({name:"侯东骁"});
  const student2 = await Student.create({name:"季杰"});

  const company = await CLASS.create({name:"环境1班"});

  await student1.setCLASS(company);
  await student2.setCLASS(company);

  

  






})();